//
//  GuideViewController.m
//  Police_NB
//
//  Created by haoyi on 14-7-22.
//  Copyright (c) 2014年 Hooy1. All rights reserved.
//

#import "GuideViewController.h"

@implementation GuideViewController


+ (GuideViewController *)sharedGuide
{
    @synchronized(self)
    {
        static GuideViewController *sharedGuide = nil;
        if (sharedGuide == nil)
        {
            sharedGuide = [[self alloc] init];
        }
        return sharedGuide;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self hideNaviBar:YES];
    
    NSArray *imageNameArray = [NSArray arrayWithObjects:@"办事指南.jpg", @"咨询投诉.jpg", @"开锁求助.jpg", @"微信报警.jpg",@"自助移车.jpg",@"违法犯罪举报.jpg",@"重名查询.jpg",@"事故快撤.jpg", nil];
    
    _guideScrollView = [[UIScrollView alloc] initWithFrame:
                        CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _guideScrollView.pagingEnabled = YES;
    _guideScrollView.contentSize = CGSizeMake(self.view.frame.size.width * imageNameArray.count,
                                              self.view.frame.size.height);
    _guideScrollView.showsHorizontalScrollIndicator = NO;
    _guideScrollView.delegate = self;
    _guideScrollView.bounces=NO;
    
    [self.view addSubview:_guideScrollView];
    
    UIImageView *imageView;
    for (int i = 0; i < imageNameArray.count; i++) {
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i,
                                                                  0.f,
                                                                  self.view.frame.size.width,
                                                                  self.view.frame.size.height)];
        imageView.backgroundColor = [UIColor clearColor];
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:[imageNameArray objectAtIndex:i]];
        [_guideScrollView addSubview:imageView];
        
//        if (i == imageNameArray.count - 1) {
        
            UIButton *enterButton = [UIButton buttonWithType:0];
            enterButton.frame = CGRectMake(100, ScreenHeight - 65, ScreenWidth - 200, 35);
            enterButton.backgroundColor = [UIColor whiteColor];
        
            [enterButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [enterButton setTitle:@"开始使用" forState:UIControlStateNormal];
            [enterButton addTarget:self action:@selector(pressEnterButton)
                  forControlEvents:UIControlEventTouchUpInside];
            enterButton.hidden=_btnhidView;
            [imageView addSubview:enterButton];
        
//        }
    }
    pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height -30, self.view.bounds.size.width, 30)];
    pageControl.enabled = NO;
    pageControl.numberOfPages = imageNameArray.count;
    [self.view addSubview:pageControl];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated
{

    [super viewWillAppear:animated];
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    [_guideScrollView setContentOffset:CGPointZero];
    pageControl.currentPage = 0;
}

- (void)viewDidDisappear:(BOOL)animated
{
    
    [[UIApplication sharedApplication] setStatusBarHidden:NO];

    [super viewDidDisappear:animated];
}

- (void)pressEnterButton{
    
    if (_IsFirstjoin==YES) {
        
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        
        [[UIApplication sharedApplication]keyWindow].rootViewController=mainStoryBoard.instantiateInitialViewController;
        
        [self.navigationController popToRootViewControllerAnimated:NO];
        
        
        
    }else{
        
   [self.navigationController popToRootViewControllerAnimated:YES];
        
    }

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    pageControl.currentPage = scrollView.contentOffset.x/scrollView.bounds.size.width;
}
-(BOOL)hidesBottomBarWhenPushed{
    return YES;
}
@end
